package com.sz.service.impl;

import com.sz.dao.SetmealDao;
import com.sz.pojo.Setmeal;
import com.sz.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SetmealServiceImpl implements SetmealService {

    @Autowired
    private SetmealDao setmealDao;
    @Override
    public void add(Setmeal setmeal, List<Integer> checkgroupIds) {
        //添加套餐
        setmealDao.add(setmeal);
        //获取套餐的id
        Integer setmealId = setmeal.getId();
        //遍历选中的检查组id集合 非空判断
        if(checkgroupIds != null){
            //添加套餐与检查组的关系
            for (Integer checkgroupId:checkgroupIds){
                setmealDao.addSetmealCheckGroup(setmealId,checkgroupId);
            }
        }
    }
}
